﻿package com.winmastergames.multiplayer 
{
	import com.winmastergames.lolgame.engine;
	import com.winmastergames.lolgame.multiplayerHud;
	/**
	 * ...
	 * @author     Advanced Flash Engine in ActionScript 3.
    Copyright (C) 2009  Dean Gardiner, Taylor Lodge

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
	 */
	public class messageParser
	{
		public static var multi:MultiplayerClient;
		public static function parseMessage(tier1:String, tier2:String, command:String, argument:String):void
		{
			multi = engine.mp;
			switch(tier1)
			{
				case "Server":
					parseT1Server(tier2, command, argument);
					break;
				case "Client":
					parseT1Client(tier2, command, argument);
					break;
			}
		}
		public static function parseT1Server(tier2:String, command:String, argument:String):void
		{
			switch(tier2)
			{
				case "Messaging":
					break;
				case "Players":
					switch(command)
					{
						case "sendPing":
							var now:Date = new Date();
							var pingSent:Number = Number(argument.toString());
							var pingRecv:Number = now.milliseconds + (now.seconds * 1000);
							var lag:Number = pingRecv - pingSent;
							engine.mp.hud.setPing(lag.toString());
							break;
					}
					break;
				case "Enemies":
					break;
			}
		}
		public static function parseT1Client(tier2:String, command:String, argument:String):void
		{
			switch(tier2)
			{
				case "Moderate":
					break;
				case "Messaging":
					break;
				case "Priority":
					switch(command)
					{
						case "WhoAreYou":
							if (argument == "whoareyou")
							{
								multi.clientSocketConnection.sendMessage("Client->Priority->WhoAreYou->GameClient");
								trace("Sent 'W.A.Y' Response");
							}
							break;
					}
					break;
			}
		}
	}

}